<?php
$panelSettings = Zend_Json::decode($this->panel->settings);
$align = $panelSettings['align'];
?>
<div id="<?php echo $this->panel->getDivID() ?>">
    <fieldset><legend><?php echo $this->_translate->_('User.Amenities.Main','title');?></legend>
    <div class="RM_amenities_unit_amenities_container" style="text-align:<?php echo $panelSettings['align'];?>">
        <div id="RM-amenities-module-display">
            <img src="<?php echo RM_Environment::getConnector()->getRootURL(); ?>RM/userdata/images/system/small/loading_bar.gif" border="0">
        </div>
    </div>
    </fieldset>
</div>

<script type="text/javascript">
// Send an AJAX request for the amenities data for this unit.
var conn = new Ext.data.Connection();
var request = {
    url: RM.Common.AssembleURL({
        controller : 'Amenities',
        action: 'getunitamenitiesjson',
        parameters: [
            {
                name: 'unitID',
                value: <?php echo $this->unit->getId(); ?>
            }
        ]
    }),
    method: 'POST',
    success: function(responseObject) {
        var jsondata = Ext.util.JSON.decode(responseObject.responseText);
        var data = jsondata.amenities;
        var config = jsondata.config;

        var html = ''; var iconURL = '';
        var i = 0;for (i; i < data.length; i++ ){
            // create an amenities cell...

            iconURL = RM.RootURL + "RM/userdata/images/Amenities/" + data[i].icon_url;

            if (data[i].info_url !=="" ){
                html += "<table width='1' align='left' class='rm-module-amenities-amenity-cell-table'><tr><td><div class='rm-module-amenities-amenity-cell-inner'><a href='" + data[i].info_url + "'><img src='" + iconURL + "' alt='' height='" + config.icon_height + "'><br/><div class='rm-module-amenities-amenity-cell-inner-textlabel'>" + data[i].name + "</div></a></div></td></tr></table>";
            } else {
                html += "<table width='1' align='left' class='rm-module-amenities-amenity-cell-table'><tr><td><div class='rm-module-amenities-amenity-cell-inner'><img src='" + iconURL + "' alt='' height='" + config.icon_height + "'><br/><div class='rm-module-amenities-amenity-cell-inner-textlabel'>" + data[i].name + "</div></div></td></tr></table>";
            }

        }
        document.getElementById("RM-amenities-module-display").innerHTML=html;
    },
    failure: function(){}
};
conn.request(request);
</script>